package table_data;


import beans.IndicatorList;
import common.Utils;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class TransIndicatorListKbseToLocal {
    public static void main(String[] args) {
        try {
            File file=new File("C:\\Users\\ts647\\Desktop\\output_indicator_list");//文件不存在则创建
            FileOutputStream fos=new FileOutputStream(file,true);//第二个参数为true代表追加，为false(默认)为覆盖
            Class.forName(Utils.driver);//加载KBase驱动
            //可以直接读取视图，库名不写，直接查视图即可
            Connection conn = DriverManager.getConnection(Utils.indicator_list_url, Utils.user, Utils. password);// 获取连接
            Statement statement = conn.createStatement();//得到声明
            //当kbase某列值为null（看起来就是空）时，该列也存在，例子："unit_type_code":""
            ResultSet rs = statement.executeQuery("SELECT * FROM NAVIFREQ_TOP50_CLASSIFY");//执行SQL语句返回结果集
            while (rs.next()) { //循环输出结果集
                String zhi_biao=rs.getString("指标");
                String zhi_biao_lei_bie=rs.getString("指标类别");
                String zhi_biao_pai_xu=rs.getString("指标排序");
                String jing_lian_biao_ti=rs.getString("精炼标题");
                String biao_zhun_dan_wei=rs.getString("标准单位");
                String jing_lian_biao_ti_pai_xu=rs.getString("精炼标题排序");
                String zhuan_huan_dan_wei=rs.getString("转换单位");
                String gong_shi_zhi_biao=rs.getString("公式指标");
                String jian_suo_zhi_biao=rs.getString("检索指标");

                IndicatorList u= new IndicatorList(zhi_biao,zhi_biao_lei_bie,zhi_biao_pai_xu,jing_lian_biao_ti,biao_zhun_dan_wei,jing_lian_biao_ti_pai_xu,zhuan_huan_dan_wei,gong_shi_zhi_biao,jian_suo_zhi_biao);
                fos.write(u.toString().getBytes());
            }
            fos.close();
            rs.close();//关闭结果集
            conn.close();//关闭数据库连接
        } catch (Exception e) {
            System.out.print("KBase ERROR:" + e.getMessage());
        }
    }
}

